import { createRouter, createWebHistory } from 'vue-router'
import Layout from "@/layout/Layout.vue"

const routes = [
  {
    path: '/login',
    name: 'login',
    title: "登陆",
    isHidden: true,
    component: () => import("@/views/login/index.vue"),
  },
  {
    path: '/',
    name: 'home',
    component: Layout,
    redirect: "/home",
    children: [
      {
        path: "/home",
        component: () => import("@/views/home/index.vue"),
        name: "Index",
        title: "首页",
        meta: {},
      },
      {
        path: "/bg/page",
        title: "页面动画",
        component: () => import("@/views/bg/index.vue"),
        name: "page",
        meta: {},
      },
    ],
  },
]

const getMenu = () => {
  // const result = [...routes];
  const loop = (arr) => {
    arr = arr.filter((p) => !p.isHidden);
    arr =   arr.map((p) => {
      return {
        key: p.path,
        label: p.title,
        title: p.title,
        children : p.children? loop(p.children) : undefined
      }
    });
    return arr;
  };
  return loop(routes);
};

const menuData = getMenu()

console.log('menuData', menuData)

export { menuData };


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
})

export default router
